﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Common.Logging;
using KeepAliveHttp.Http;

namespace KeepAliveHttp
{
    /// <summary>
    /// connection 的摘要说明
    /// </summary>
    public class Connection : IHttpHandler
    {
        private static readonly ILog logger = LogManager.GetLogger(typeof(Connection));
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.ContentType = "text/plain";
            try
            {
                //假装登录成功，返回一个会话标识
                WebClientConnection webClientConnection = new WebClientConnection(null);
                SessionManager.AddConnection(webClientConnection);
                context.Response.Write(webClientConnection.SessionId);
            }
            catch (Exception ex)
            {
                logger.Error("创建连接发生错误:" + ex.Message);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}